package com.example.personal.mvvm.fragment

import android.content.Intent
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.personal.R
import com.example.personal.mvvm.activity.AnalyseActivity
import com.example.personal.mvvm.activity.MyAttentionListActivity
import com.gsafety.library.Widgets.dia.OnSweetClickListener
import com.gsafety.library.Widgets.dia.SweetAlertDia
import com.gsafety.libraryktx.base.BaseFragment
import com.gsafety.libraryktx.config.Constant
import com.gsafety.libraryktx.core.RouterConstants
import com.gsafety.libraryktx.manager.UserManager
import com.gsafety.libraryktx.util.AppUtil
import com.jeremyliao.liveeventbus.LiveEventBus
import kotlinx.android.synthetic.main.personal_fragment_layout.*

@Route(path = RouterConstants.PERSONAL_FRAGMENT)
 class PersonalFragment : BaseFragment() {

    override fun initView(view: View?) {
        initcode()
        rl_attention.setOnClickListener {
            ARouter.getInstance().build(RouterConstants.ACCOUNT_ACTIVITY).navigation()
        }
        rl_secret.setOnClickListener {
            ARouter.getInstance().build(RouterConstants.MODIFY_SECRET_ACTIVITY).navigation()
        }
        cl_analyse.setOnClickListener{
            var intent = Intent(activity, AnalyseActivity::class.java)
            startActivity(intent)
        }

        cl_my_save.setOnClickListener {
            var intent = Intent(activity, MyAttentionListActivity::class.java)
            startActivity(intent)
        }
        exit.setOnClickListener {
            mContext?.also {
                AppUtil.showConfirmDia(it, "是否退出登录?", object : OnSweetClickListener {
                    override fun onClick(sweetAlertDialog: SweetAlertDia) {
                      AppUtil.exitLogin()
                    }
                }, object : OnSweetClickListener {
                    override fun onClick(sweetAlertDialog: SweetAlertDia) {
                    }
                }, true)
            }
        }
    }

    override fun initData() {
        var loginBean=UserManager.getInstance().getUser()
        loginBean?.let {
            tv_username.text=it.userName
            tv_company.text=it.orgName
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.personal_fragment_layout
    }
    private  fun initcode() {
        var codes = UserManager.getInstance().appModelCodes()
        codes?.also {
            //我的关注
            if (!it.contains(Constant.CODE_WDGZ)) {
                cl_my_save.visibility = View.INVISIBLE
            }
            //我的点评
            if (!it.contains(Constant.CODE_WDDP)) {
                cl_my_commend.visibility = View.INVISIBLE
            }
            //统计分析
            if (!it.contains(Constant.CODE_TJFX)) {
                cl_analyse.visibility = View.INVISIBLE
            }
            //账号管理
            if (!it.contains(Constant.CODE_ZHGL)) {
                rl_attention.visibility = View.INVISIBLE
            }
            //修改密码
            if (!it.contains(Constant.CODE_XGMM)) {
                rl_secret.visibility = View.INVISIBLE
            }
            //背景颜色
            if (!it.contains(Constant.CODE_BJYS)) {
                rl_skin.visibility = View.INVISIBLE
            }
        }
    }


}